package pl.maslany.angielski;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesUtil {
	
	public static final String MAIL_HOST = "smtp.host";
	public static final String MAIL_PORT = "smtp.port";
	public static final String MAIL_USER = "smtp.user";
	public static final String MAIL_PASSWD = "smtp.passwd";
	public static final String MAIL_FROM = "smtp.sender";
	public static final String MAIL_TO = "smtp.receivers";
	public static final String SHUFFLE_TESTS = "shuffle.test";
	
	
	static Properties properties;
	
	static {
	    properties = new Properties();
	    try {
	        properties.load(new FileInputStream(System.getProperty("user.dir") + "/app.properties"));
	    } catch (IOException e) {
	    }
	}
	
	public static String getProperty(String key) {
		return properties.getProperty(key);
	}
	
	public static boolean getBooleanProperty(String key) {
		return Boolean.parseBoolean(getProperty(key));
	}
	
	public static boolean sendEmail() {
		return properties.containsKey(MAIL_HOST) &&
				properties.containsKey(MAIL_PORT) &&
				properties.containsKey(MAIL_FROM) &&
				properties.containsKey(MAIL_PASSWD) &&
				properties.containsKey(MAIL_TO) &&
				properties.containsKey(MAIL_USER);
	}
	
	public static boolean shuffle() {
		return getProperty(SHUFFLE_TESTS) != null && getBooleanProperty(SHUFFLE_TESTS);
	}
}
